package com.bluezone.dec.system.service.impl;

import com.bluezone.dec.common.PageEntity;
import com.bluezone.dec.system.dao.LogDOMapper;
import com.bluezone.dec.system.entity.LogDO;
import com.bluezone.dec.system.service.LogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LogServiceImpl implements LogService {

    @Autowired
    private LogDOMapper logDOMapper;

    @Override
    public int save(LogDO logDO) {
        return logDOMapper.insert(logDO);
    }

    @Override
    public int update(LogDO logDO) {
        return logDOMapper.update(logDO);
    }

    @Override
    public LogDO get(String id) {
        return logDOMapper.selectById(id);
    }

    @Override
    public int remove(String id) {
        return logDOMapper.deleteById(id);
    }

    @Override
    public int batchRemove(String... ids) {
        return logDOMapper.batchRemove(ids);
    }

    @Override
    public PageEntity<LogDO> findByParams(Map<String, Object> params) {

        int pageNum = (int) params.get("pageNum");// 页码
        int pageSize = (int) params.get("pageSize"); // 页大小

        List<LogDO> list = null;
        PageInfo<LogDO> pageInfo = null;

        if (pageNum != 0 && pageSize != 0) {
            PageHelper.startPage(pageNum, pageSize);
            list = logDOMapper.findByParams(params);
            pageInfo = new PageInfo(list);
        }

        return PageEntity.toPageEntity(pageInfo);
    }

    @Override
    public List<LogDO> findAll() {
        return logDOMapper.findByParams(new HashMap<>());
    }
}
